/**
 * @desc 深拷贝（递归）
 * @param data
 * @return {any}
 */
function deepClone(data: any) {
    let copy;
    if (null == data || "object" !== typeof data) return data;
    if (data instanceof Date) {
        copy = new Date();
        copy.setTime(data.getTime());
        return copy;
    }

    if (data instanceof Array) {
        copy = [];
        for (let i = 0, len = data.length; i < len; i++) {
            copy[i] = deepClone(data[i]);
        }
        return copy;
    }

    if (data instanceof Object) {
        copy = {};
        for (let attr in data) {
            if (data.hasOwnProperty(attr)) copy[attr] = deepClone(data[attr]);
        }
        return copy;
    }

    throw new Error("无法复制数据，不支持此数据类型");
}

export default {
    deepClone,
}
